﻿using AngleExpress.viewmodel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AngleExpress
{

    public delegate void HasReadNotify(string id);
    /// <summary>
    /// Notify.xaml 的交互逻辑
    /// </summary>
    public partial class Notify : Window
    {
        readonly NotifysViewModel viewModel;
        NotifyMsg curNotifyMsg;
        readonly HasReadNotify hasReadNotify;

        public Notify(List<NotifyMsg> list, HasReadNotify callback)
        {
            InitializeComponent();
            viewModel = new NotifysViewModel();
            viewModel.Show = ShowWhat.Table;
            foreach(var msg in list)
            {
                viewModel.NotifyList.Add(msg);
            }
            this.DataContext = viewModel;
            hasReadNotify = callback;
        }

        private void ShowDetail(object sender, RoutedEventArgs e)
        {
            var btn = sender as Button;
            curNotifyMsg = btn.DataContext as NotifyMsg;
            DetailGrid.DataContext = curNotifyMsg;
            viewModel.Show = ShowWhat.Detail;
        }

        private void Goback(object sender, RoutedEventArgs e)
        {
            viewModel.Show = ShowWhat.Table;
        }

        private void RegisterRead(object sender, RoutedEventArgs e)
        {
            if (curNotifyMsg != null)
            {
                viewModel.NotifyList.Remove(curNotifyMsg);
                hasReadNotify(curNotifyMsg.ID);
            }
            viewModel.Show = ShowWhat.Table;
        }
    }
}
